import { request, BaseResponse, downloadFile } from '@/utils/request';
/**
 * @description 获取其列表
 * @param {Namespace} isMock
 * @param isGetDataDirectly
 * @returns
 */

/**
 * 数据区域
 * 单元管理
 */
export function getdomainList(query: string) {
  return request<BaseResponse<Array<Namespace.RegionObject>>>(
    {
      url: `/sys/region/unitregiondata/${query}`,
      method: 'get',
    },
    {
      isMock: false,
      isGetDataDirectly: false,
    },
  );
}

/** 搜索类树形
 *  父级单元
 */
export function getUnitList(query: { unitId?: string; type: string }, regionId: number) {
  return request<BaseResponse<Array<Namespace.UnitObject>>>(
    {
      url: `/sys/unit/getunitdata/${regionId}`,
      method: 'get',
      params: query,
    },
    {
      isMock: false,
      isGetDataDirectly: false,
    },
  );
}

/**树形数据 */
export function getTreeList(regionId: number) {
  return request<BaseResponse<Namespace.unitTree>>(
    {
      url: `/sys/unit/getunittree/${regionId}`,
      method: 'get',
    },
    {
      isMock: false,
      isGetDataDirectly: false,
    },
  );
}

/** 单元数据 */
export function getUnitId(query: { unitId: string | any }) {
  return request<BaseResponse<Namespace.UnitObject>>(
    {
      url: '/sys/unit/getdata',
      method: 'get',
      params: query,
    },
    {
      isMock: false,
      isGetDataDirectly: false,
    },
  );
}

/** 单元修改 */
export function getUnitUpdate(query: Namespace.UnitObjectSaveUp) {
  return request<BaseResponse>(
    {
      url: '/sys/unit/updata',
      method: 'post',
      data: query,
      headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    },
    {
      isMock: false,
      isGetDataDirectly: false,
      successMsg: '修改成功',
    },
  );
}

/** 单元新增 */
export function getUnitSave(query: Namespace.UnitObjectSaveUp) {
  return request<BaseResponse>(
    {
      url: '/sys/unit/save',
      method: 'post',
      data: query,
      headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    },
    {
      isMock: false,
      isGetDataDirectly: false,
      successMsg: '新增成功',
    },
  );
}

/** 单元删除 */
export function getUnitDelete(query: { unitId: string }) {
  return request<BaseResponse>(
    {
      url: '/sys/unit/remove',
      method: 'post',
      data: query,
      headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    },
    {
      isMock: false,
      isGetDataDirectly: false,
      successMsg: '删除成功',
    },
  );
}

/** 元素提交 */
export function saveUnitJson(data: {
  jsondata: string;
  id: string | number;
  permissions_data: string;
}) {
  return request<BaseResponse>(
    {
      url: '/sys/unit/saveunitjson',
      method: 'post',
      data,
    },
    {
      isMock: false,
      isGetDataDirectly: false,
      successMsg: '提交成功',
    },
  );
}

/** 获取多语言编号 */
export function GetLanguaggeNum(data: {
  jsondata: string;
  id: string | number;
  permissions_data: string;
}) {
  return request<BaseResponse>(
    {
      url: '/sys/unit/updatelanguagejson ',
      method: 'post',
      data,
    },
    {
      isMock: false,
      isGetDataDirectly: false,
      successMsg: '获取成功',
    },
  );
}

/** 移动端元素提交 */
export function savePhoneUnitJson(data: {
  jsondata: string;
  id: string | number;
  permissions_data: string;
}) {
  return request<BaseResponse>(
    {
      url: '/sys/unit/mobile/saveunitjson',
      method: 'post',
      data,
    },
    {
      isMock: false,
      isGetDataDirectly: false,
      successMsg: '提交成功',
    },
  );
}

/** 元素提交 */
export function getUnitJson(query: { id: string | number }) {
  return request<BaseResponse<string>>(
    {
      url: '/sys/unit/getunitjson',
      method: 'get',
      params: query,
    },
    {
      isMock: false,
      isGetDataDirectly: false,
    },
  );
}

/** 获取移动端页面json */
export function getPhoneUnitJson(query: { id: string | number }) {
  return request<BaseResponse<string>>(
    {
      url: '/sys/unit/mobile/getunitjson',
      method: 'get',
      params: query,
    },
    {
      isMock: false,
      isGetDataDirectly: false,
    },
  );
}

/** 快速页面验证 */
export function getTabledatas(query: { unit_code: string; region_id: string }) {
  return request<BaseResponse<Array<Namespace.tabledatasType>>>(
    {
      url: '/sys/parameter/tabledatas',
      method: 'get',
      params: query,
    },
    {
      isMock: false,
      isGetDataDirectly: false,
    },
  );
}

/** 快速页面生成 */
export function Postgeneratepage(data: Array<Namespace.generatepageList> | any) {
  return request<BaseResponse>(
    {
      url: '/sys/unit/generatepage',
      method: 'post',
      data,
    },
    {
      isMock: false,
      isGetDataDirectly: false,
    },
  );
}

/**
 * 元素开启权限接口
 */

export function elementPermissions(data: Namespace.elementPermissions) {
  return request<BaseResponse>(
    {
      url: '/sys/compermissions/saveelementpe',
      method: 'post',
      data,
    },
    {
      isMock: false,
      isGetDataDirectly: false,
    },
  );
}

/**
 * 单元权限接口
 */

export function unitPermissions(data: Namespace.unitPermissions) {
  return request<BaseResponse>(
    {
      url: '/sys/compermissions/saveunitpe',
      method: 'post',
      data,
    },
    {
      isMock: false,
      isGetDataDirectly: false,
    },
  );
}

/** 导出单元 */
export function exportUnit(query: { ids: Array<any> }) {
  return downloadFile(
    {
      url: '/sys/unit/deriveunitdata',
      method: 'post',
      data: query,
      headers: { 'Content-Type': 'application/json' },
      responseType: 'blob',
    },
    'unitData.xml',
  );
}

export function ImportUnit(data: FormData) {
  return request<BaseResponse>(
    {
      url: '/sys/unit/importunitdata',
      method: 'post',
      headers: { 'Content-Type': 'multipart/form-data' },
      data,
    },
    {
      isMock: false,
      isGetDataDirectly: false,
      successMsg: '上传成功',
    },
  );
  // return requestForm(
  //   '/sys/unit/importunitdata',
  //   data
  // );
}
